<?
/*----------------------------------------------------------------------
          (C) Bobtail-Bear 2006 	小飞熊新一代下载系统
          	代码编写：小飞熊	版权所有：小飞熊[L.F.Bear]
				官方网站/技术支持：http://www.lfbear.cn
------------------------------------------------------------------------
          (C) Bobtail-Bear 2006 	L.F.Bear's New Download Sysytem
          	Powered by L.F.Bear  Copyright L.F.Bear's Home(R)
               Official Web/Support：http://www.lfbear.cn
-----------------------------------------------------------------------*/

//本页脚本功能：日志管理
$thispage="weblog.php";
echo ("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
require("../function.php");
require("../include/config.inc.php");
require("check.php");

$per=$weblog_per;//每页记录数目
$reserve=$weblog_reserve;//系统保留日志数目
if ($_COOKIE[status]=="login" && $_SESSION[login]=="yes")
{
$yourname=$_COOKIE[yourname];
$level=$_SESSION[level];
if(!checklevel($level,"system"))
	{$msg_title="系统信息：权限不足";
	$msg_link="login.php";
	$msg="您无法进行此项管理操作！<br><br>原因：您所在的用户组没有该权限。<br><br>";
	weblog("日志管理","无权限操作，被系统拦截！","red",$yourname,"触发页面：weblog.php");
	require("error.php");
	die;}

$action=$_GET[action];
$page=$_GET[page];
$job=$_GET[job];
switch ($action){
case login:
$op_name="登陆日志";
$op_file="../include/weblog_login.php";
unset($info);
if (!file_exists($op_file)){$op_count=0;$info="<tr bgcolor='#FFFFFF'><td colspan=\"5\">暂时没有日志</td></tr>";}

else
	{$op_data=file($op_file);
	$op_count=count($op_data);
	$op_count--;
	if($op_count<=$reserve) {$hide="hidden";$unhide="visible";} else {$hide="visible";$unhide="hidden";}
//分页开始
	if($op_count>$per){
	if($page=="") $page=1;
	$thebging=$op_count-($page-1)*$per;
	$theend=$op_count-($page*$per)+1;
	if($theend<=1) $theend=1;
	for ($i=$thebging;$i>=$theend;$i--) { 
	$list_info=explode("|",$op_data[$i]);
	$info.="<tr bgcolor='#FFFFFF'><td>$list_info[0]$list_info[1]</td><td>$list_info[2]</td><td>$list_info[3]</td><td>$list_info[4]：<font color=$list_info[6]>$list_info[5]</font></td><td>$list_info[7]</td></tr>";
	$page_num=ceil(($op_count)/$per);
	}		/* 数页数的样子，现在不要了，就是因为破lzy说的
	for ($j=1;$j<=$page_num;$j++)
		$show_page.="[<a href='weblog.php?action=login&page=$j'>第 $j 页</a>]";
		*/
		}
	else{$page_num=1;$page=0;
for ($i=$op_count; $i>=1; $i--) {
	$list_info=explode("|",$op_data[$i]);
$info.="<tr bgcolor='#FFFFFF'><td>$list_info[0]$list_info[1]</td><td>$list_info[2]</td><td>$list_info[3]</td><td>$list_info[4]：<font color=$list_info[6]>$list_info[5]</font></td><td>$list_info[7]</td></tr>";
}
}}
//分页结束

//清理多余日志
if($job=="clear"){
$new="<? die(\"Forbidden Access!\");?>\n";
for($k=$op_count-$reserve+1;$k<=$op_count;$k++)
{
$new.=$op_data[$k];
}
writef($op_file,$new,"w");
$state="清理完毕[<a href='weblog.php?action=$action'>请刷新本页</a>]";
$hide="hidden";
}
break;

case admin:
$op_name="操作日志";
$op_file="../include/weblog_operate.php";
unset($info);
if (!file_exists($op_file)){$op_count=0;$info="<tr bgcolor='#FFFFFF'><td colspan=\"5\">暂时没有日志</td></tr>";}

else
	{$op_data=file($op_file);
	$op_count=count($op_data);
	$op_count--;
	if($op_count<=$reserve) {$hide="hidden";$unhide="visible";} else {$hide="visible";$unhide="hidden";}
//分页开始
	if($op_count>$per){
	if($page=="") $page=1;
	$thebging=$op_count-($page-1)*$per;
	$theend=$op_count-($page*$per)+1;
	if($theend<=1) $theend=1;
	for ($i=$thebging;$i>=$theend;$i--) { 
	$list_info=explode("|",$op_data[$i]);
	$info.="<tr bgcolor='#FFFFFF'><td>$list_info[0]$list_info[1]</td><td>$list_info[2]</td><td>$list_info[3]</td><td>$list_info[4]：<font color=$list_info[6]>$list_info[5]</font></td><td>$list_info[7]</td></tr>";
	$page_num=ceil(($op_count)/$per);
	}
		/* 数页数的样子，现在不要了，就是因为破lzy说的
		for ($j=1;$j<=$page_num;$j++)
		$show_page.="[<a href='weblog.php?action=admin&page=$j'>第 $j 页</a>]";
		*/
		}
	else{$page_num=1;$page=0;
for ($i=$op_count; $i>=1; $i--) {
	$list_info=explode("|",$op_data[$i]);
$info.="<tr bgcolor='#FFFFFF'><td>$list_info[0]$list_info[1]</td><td>$list_info[2]</td><td>$list_info[3]</td><td>$list_info[4]：<font color=$list_info[6]>$list_info[5]</font></td><td>$list_info[7]</td></tr>";
}
}}

//清理多余日志
if($job=="clear"){
$new="<? die(\"Forbidden Access!\");?>\n";
for($k=$op_count-$reserve+1;$k<=$op_count;$k++)
{
$new.=$op_data[$k];
}
writef($op_file,$new,"w");
$state="清理完毕[<a href='weblog.php?action=$action'>请刷新本页</a>]";
$hide="hidden";
}
break;

default:
die("Error Parameter,Forbidden Access!");
break;
}
$nbsp="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
$act="?".$action;
$msg_="重要信息";
$msg_color="#FF8C1A";
require("msg.php");

//显示上、下页码部分
if($page==0) $up_down="暂无分页";
elseif($page==1) {$page_down=$page+1;$up_down="当前第[$page]页$nbsp</a>[<a class=\"arrowhead\" disabled>9</a>] [<a class=\"arrowhead\" disabled>7</a>] [<a href='weblog.php?action=$action&page=$page_down' class=\"arrowhead\" title=\"下一页\">8</a>]  [<a href='weblog.php?action=$action&page=$page_num' class=\"arrowhead\" title=\"末页\">:</a>]";}
elseif($page==$page_num) {$page_up=$page-1;$up_down="当前第[$page]页$nbsp</a>[<a href='weblog.php?action=$action&page=1' class=\"arrowhead\" title=\"首页\">9</a>] [<a href='weblog.php?action=$action&page=$page_up' class=\"arrowhead\" title=\"上一页\">7</a>] [<a class=\"arrowhead\" disabled>8</a>]  [<a class=\"arrowhead\" disabled>:</a>]";}
else {$page_down=$page+1;$page_up=$page-1; $up_down="当前第[$page]页$nbsp</a>[<a href='weblog.php?action=$action&page=1' class=\"arrowhead\" title=\"首页\">9</a>] [<a href='weblog.php?action=$action&page=$page_up' class=\"arrowhead\" title=\"上一页\">7</a>] [<a href='weblog.php?action=$action&page=$page_down' class=\"arrowhead\" title=\"下一页\">8</a>]  [<a href='weblog.php?action=$action&page=$page_num' class=\"arrowhead\" title=\"末页\">:</a>]";}


print <<<EOT
<link href="images/css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.massage{color:#993399;
cursor:help;
text-decoration:none;}
.subtitle{
color:#3300FF;
font-family:"宋体";
font-size:12px;
font-weight:bold;}
-->
</style>
<body bgcolor="#DDF1FF">
<table width="750" border="1" align="center" cellpadding=4 cellspacing=0 bordercolor="#ACC1FC" heoght=400>
  <tr bgcolor='#ACC1FC'>
    <td width="718" colspan="5"><a class="title">欢迎您：$yourname 登陆管理程序</a></td>
  </tr>
  <tr bgcolor='#FFFFFF'>
    <td colspan="5" bgcolor="#EBE9ED" class="comments-title">日志管理--&gt;$op_name</td>
  </tr>
  	 <tr bgcolor='#FFFFFF'>
    <td colspan="5" align="right"><b><a style="visibility:$unhide" title="只有日志大于 $reserve 条时才可以进行清理">[暂时无法清理日志]</a><a href='weblog.php?action=$action&job=clear' title="保留日志数为 $reserve 条，只能清除多余部分！" style="visibility:$hide">[清理多余日志]</a>$state</b></td>
  </tr>
  <tr bgcolor='#FFFFFF'>
    <td class="subtitle" width="150"><div align="center">记录时间</div></td>
    <td class="subtitle" width="100"><div align="center">操作者</div></td>
    <td class="subtitle" width="100"><div align="center">IP地址</div></td>
    <td class="subtitle" width="230"><div align="center">操作动作</div></td>
    <td class="subtitle" width="70"><div align="center">备注</div></td>
  </tr>
  		$info
  <tr bgcolor='#FFFFFF'>
    <td colspan="5" align="left"><a  class="subtitle">共 $op_count 条,分 $page_num 页，$per 条/页 $nbsp $up_down</td>
  </tr>
</table>
EOT;
require("footer.php");
}
?>